package cmq.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ProjectName: interview
 * @Package: java.cmq.socket
 * @ClassName: BIO
 * @Author: chenmengqi
 * @Description:
 * @Date: 2020/2/18 4:30 下午
 * @Version: 1.0
 */
public class BIOServer {
    public static void main(String[] args) {
        try {

            byte[] bytes = new byte[1024];

            ServerSocket serverSocket = new ServerSocket();

            serverSocket.bind(new InetSocketAddress(3000));
            while (true) {
                // 阻塞，等待连接
                System.out.println("wait connect ...");
                Socket accept = serverSocket.accept();
                System.out.println("connect successful");



                // 接收数据
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(accept.getInputStream()));
                String line = bufferedReader.readLine();
                System.out.println("data come from server：" + line);
                bufferedReader.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
